﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace 城市天然气管道风险管理与决策系统
{
    public partial class Form_menu_1_2 : Form
    {
        public Form_menu_1_2()
        {
            InitializeComponent();
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            textBox10.ReadOnly = false;
            textBox5.ReadOnly = false;
            textBox6.ReadOnly = false;
            textBox7.ReadOnly = false;
            textBox8.ReadOnly = false;
            textBox9.ReadOnly = false;
            richTextBox1.ReadOnly = false;
            textBox11.ReadOnly = false;
            textBox12.ReadOnly = false;
        }

        private void Form_menu_1_2_Load(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textBox5.ReadOnly = true;
            textBox6.ReadOnly = true;
            textBox7.ReadOnly = true;
            textBox8.ReadOnly = true;
            textBox9.ReadOnly = true;
            textBox10.ReadOnly = true;
            textBox11.ReadOnly = true;
            textBox12.ReadOnly = true;
            richTextBox1.ReadOnly = true;

            textBox1.Text = GlobalData.default_pipeline.Id.ToString();
            textBox2.Text = GlobalData.default_pipeline.Name;
            textBox4.Text = GlobalData.default_pipeline.StartLocation;
            textBox3.Text = GlobalData.default_pipeline.EndLocation;
            if (GlobalData.default_pipeline.Logo) comboBox1.SelectedIndex = 0;
            else comboBox1.SelectedIndex = 1;
            textBox5.Text = GlobalData.default_pipeline.DesignThick.ToString();
            textBox6.Text = GlobalData.default_pipeline.RealThick.ToString();
            textBox7.Text = GlobalData.default_pipeline.Diameter.ToString();
            textBox8.Text = GlobalData.default_pipeline.Material;
            textBox9.Text = GlobalData.default_pipeline.Coating;
            textBox10.Text = GlobalData.default_pipeline.FixTime.ToString();
            textBox11.Text = GlobalData.default_pipeline.AccidentTime.ToString();
            textBox12.Text = GlobalData.default_pipeline.MaxPressure.ToString();
            richTextBox1.Text = GlobalData.default_pipeline.Remark_Status;
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == 0) GlobalData.default_pipeline.Logo = true;
            else GlobalData.default_pipeline.Logo = false;
            GlobalData.default_pipeline.DesignThick = double.Parse(textBox5.Text);
            GlobalData.default_pipeline.RealThick = double.Parse(textBox6.Text);
            GlobalData.default_pipeline.Diameter = double.Parse(textBox7.Text);
            GlobalData.default_pipeline.Material = textBox8.Text;
            GlobalData.default_pipeline.Coating = textBox9.Text;
            GlobalData.default_pipeline.FixTime = int.Parse(textBox10.Text);
            GlobalData.default_pipeline.AccidentTime = int.Parse(textBox11.Text);
            GlobalData.default_pipeline.MaxPressure = double.Parse(textBox12.Text);
            GlobalData.default_pipeline.Remark_Status = richTextBox1.Text;

            textBox1.ReadOnly = true;
            textBox2.ReadOnly = true;
            textBox3.ReadOnly = true;
            textBox4.ReadOnly = true;
            textBox5.ReadOnly = true;
            textBox6.ReadOnly = true;
            textBox7.ReadOnly = true;
            textBox8.ReadOnly = true;
            textBox9.ReadOnly = true;
            textBox10.ReadOnly = true;
            textBox11.ReadOnly = true;
            textBox12.ReadOnly = true;
            richTextBox1.ReadOnly = true;
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            if (printDialog1.ShowDialog() == DialogResult.OK)
                printDocument1.Print();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            string print_info = "";
            print_info += "管道ID：" + GlobalData.default_pipeline.Id.ToString();
            print_info += "\n管道名称：" + GlobalData.default_pipeline.Name;
            print_info += "\n起始位置：" + GlobalData.default_pipeline.StartLocation;
            print_info += "\n末端位置：" + GlobalData.default_pipeline.EndLocation;
            if (GlobalData.default_pipeline.Logo) print_info += "\n三柱一牌标识情况：健全";
            else print_info += "\n三柱一牌标识情况：不健全";
            print_info += "\n设计壁厚：" + GlobalData.default_pipeline.DesignThick.ToString();
            print_info += "\n实际壁厚：" + GlobalData.default_pipeline.RealThick.ToString();
            print_info += "\n管道直径：" + GlobalData.default_pipeline.Diameter.ToString();
            print_info += "\n管道材质：" + GlobalData.default_pipeline.Material;
            print_info += "\n防腐涂层：" + GlobalData.default_pipeline.Coating;
            print_info += "\n检修次数：" + GlobalData.default_pipeline.FixTime.ToString();
            print_info += "\n事故次数：" + GlobalData.default_pipeline.AccidentTime.ToString();
            print_info += "\n最大操作压力（MPa）：" + GlobalData.default_pipeline.MaxPressure.ToString();
            print_info += "\n备注：" + GlobalData.default_pipeline.Remark_Status;

            printDialog1.ShowDialog();
            e.Graphics.DrawString(print_info, richTextBox1.Font, Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y);
            printDocument1.DocumentName = GlobalData.default_pipeline.Name + "-管道信息";
        }
    }
}
